package com.oop.jihe.List;
//List三种遍历方式

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Tes_List_ergodic {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {

        //List 接口的实现子类 Vector LinkedList
        //List list = new ArrayList();
        //List list = new Vector();
        List list = new LinkedList();
        List<String> list1 = new LinkedList();

        list.add("jack");
        list.add("tom");
        list.add("鱼香肉丝");
        list.add("北京烤鸭");

        //遍历
        //1.Iterator迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object obj =  iterator.next();
            System.out.println(obj);
        }

        //2.增强for
        System.out.println("====增强for====");
        for (Object o : list){
            System.out.println("o=" + o);
        }

        //3.普通for
        System.out.println("====普通for====");
        for (int i = 0; i < list.size(); i++){
            System.out.println("对象=" + list.get(i));
        }

        //4.ListIterator迭代器遍历
        ListIterator listIterator = list.listIterator();

        System.out.println("====从前往后遍历====");
        while (listIterator.hasNext()) {
            Object next = listIterator.next();
            System.out.println(next);
        }

        System.out.println("====从后往前遍历====");
        while (listIterator.hasPrevious()) {
            Object next = listIterator.previous();
            System.out.println(next);
        }

    }
}
